const categoryModel = require('../model/categoryModel');
module.exports = {
  getAllCategories(req, res) {    
    categoryModel.getAllCategories((err, result) => {
      let response = {
        code: 0,
        message: 'error'
      }
      if (err) throw err;
      response.code = 1;
      response.message = 'ok';
      response.data = result;

      res.json(response);
    })
  },
  addNewCategory(req,res){
    // let {name,slug,classname} = req.body;
    categoryModel.addNewHero(req.body,(err,result)=>{
      if(err) throw err;
      let response = {
        code : 0,
        message : 'error'
      };
      if(result.affectedRows == 1){
        response.code = 1;
        response.message = 'ok';
      }
      res.send(response);
    })
  },
  deleteCategoryMutilple(req,res){
    categoryModel.deleteCategoryMutilple(req.query.ids,(err,result)=>{
      if(err){
        console.error(err);
      }
      let response = {
        code : 0,
        message : '失败'
      }
      if(result.affectedRows > 0){
        response.code = 1;
        response.message = '成功';
      }
      res.send(response);
    });
  }
}